package com.example.springboot.jdbc.service.impl;

import com.example.springboot.jdbc.dao.UserDao;
import com.example.springboot.jdbc.entity.User;
import com.example.springboot.jdbc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @desc用户service
 * @Author wangsh
 * @date 2018/5/5 14:01
 */
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;

	@Transactional
	@Override
	public int insert(User user) {
//		测试事物是否起作用，如果没有保存成功，则事物生效
		int a = 1/0;
		return userDao.insert(user);
	}

	@Transactional
	@Override
	public int deleteById(Integer id) {
		return userDao.deleteById(id);
	}

	@Transactional
	@Override
	public int update(User user) {
		return userDao.update(user);
	}

	@Override
	public User getById(Integer id) {
		return userDao.getById(id);
	}

}